home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1833
/
1833.xpi
/
chrome
/
yoono.jar
/
content
/
yoono
/
yoonoOverlay.js
< prev
next >
Wrap
Text File
|
2009-12-16
|
11KB
|
278 lines
/**
Toolbar yoono Firefox/Mozilla
@author : L. Quérel
Copyright 2005, Yoono SAS.
**/
// Observer qui capte les desinstallations pour lancer les proc de clean up
var uninstallObserver = {
observe:function(subject,topic,data) {
subject = subject.QueryInterface(Components.interfaces.nsIUpdateItem);
if(subject.name == "Yoono") {
YOONO_LOG.debug('Em Action: ' + data);
switch(data) {
case "item-uninstalled" :
YOONO_CMPT.uninstallAddonWhenQuitting(subject);
break;
case "item-cancel-action" :
YOONO_CMPT.uninstallWhenQuitting = false;
break;
case "item-upgraded" :
break;
}
}
},
register:function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(this, "em-action-requested", false);
},
deregister:function() {
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(this,"em-action-requested");
}
};
var yoono = {};
var yoonoObserver = {
init: function() {
try {
var ua = navigator.userAgent.toLowerCase();
if(ua.indexOf('mac os')!=-1) {
var navBar = document.getElementById('nav-bar');
if(navBar) {
var classname = navBar.getAttribute('class');
classname += ' mac' ;
navBar.setAttribute('class', classname);
}
var popup = document.getElementById("account-selector-popup");
if(popup) {
var classname = popup.getAttribute('class');
classname += ' mac' ;
popup.setAttribute('class', classname);
}
}
// Lire ds les pref la version qui a ete utilisée au lancement précédent
yoonoGlob.previousRelease = '';
try {
yoonoGlob.previousRelease = YNPREFBRANCH.getCharPref("release");
} catch(e) {
// pref not found : first install
YNPREFBRANCH.setIntPref("install_date", Math.round(new Date().getTime()/1000));
}
var extId = '{d9284e50-81fc-11da-a72b-0800200c9a66}';
var extmgr = Components.classes['@mozilla.org/extensions/manager;1'].getService(Components.interfaces.nsIExtensionManager);
yoonoGlob.currentRelease = extmgr.getItemForID(extId).version;
yoonoGlob.tosAccepted = YNPREFBRANCH.getBoolPref("tos-accepted");
// If user just updated
if(yoonoGlob.currentRelease != yoonoGlob.previousRelease) {
// releases up to 5.4 did not have a tos-accepted flag...
if(yoonoGlob.previousRelease && (yoonoGlob.previousRelease < '5.5')) {
yoonoGlob.tosAccepted = true;
YNPREFBRANCH.setBoolPref("tos-accepted", true);
}
yoonoGlob.firstReleaseRun = true;
YNPREFBRANCH.setBoolPref("first-release-run", true);
YNPREFBRANCH.setCharPref("updated.from", yoonoGlob.previousRelease); // for stats, reset after sent
YOONO_KEYVALUEDB.setKeyValue('sidebarUpdatedFrom', yoonoGlob.previousRelease);
YOONO_KEYVALUEDB.setKeyValue("sidebarFirstReleaseRun", true); // this will be reset by sidebar when it closes
} else {
yoonoGlob.firstReleaseRun = false;
YNPREFBRANCH.setBoolPref("first-release-run", false);
}
YNPREFBRANCH.setCharPref("release", yoonoGlob.currentRelease);
YOONO_KEYVALUEDB.setKeyValue('sidebarRelease', yoonoGlob.currentRelease);
yoonoGlob.firstRun = YNPREFBRANCH.getBoolPref("firstrun");
if(yoonoGlob.firstRun) {
// check the campaign cookie
var cookiesEnum = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager).enumerator;
var campaignId = 0;
while (cookiesEnum.hasMoreElements()) {
var cookie = cookiesEnum.getNext().QueryInterface(Components.interfaces.nsICookie2);
if(('www.yoono.com' == cookie.host) && ('rc' == cookie.name)) {
campaignId = cookie.value
YOONO_KEYVALUEDB.setKeyValue("sidebarMarketingCampaign", campaignId);
cookiesEnum = null;
break;
}
}
}
yoono = {};
yoono.log=YOONO_LOG;
yoono.utils=YOONO_UTILS;
yoono.server=YOONO_SERVER;
yoono.prefs=YOONO_PREFS;
yoono.yextif=YOONO_YEXTIF;
yoono.sidebar=YOONO_SIDEBAR;
yoono.storage=YOONO_STORAGE;
yoono.main=YOONO_CMPT;
yoono.bkm=YOONO_BKM;
yoono.dialogs=YOONO_DIALOGS;
YOONO_LOG.init(yoono);
YOONO_PREFS.init(yoono);
YOONO_SERVER.init(yoono);
YOONO_DIALOGS.init(yoono);
YOONO_CMPT.init(yoono);
YOONO_SIDEBAR.init(YOONO_CMPT);
YOONO_YEXTIF.init(yoono);
YOONO_STORAGE.init(yoono);
var originalSplit = '';
try {
var originalSplit = YNPREFBRANCH.getCharPref("originalSplit");
} catch(e) {}
if(!originalSplit) {
originalSplit = YNPREFBRANCH.getCharPref("autoinstall"); // can be 'full', 'discovery', 'friends'
YNPREFBRANCH.setCharPref("originalSplit", originalSplit);
}
// On first install, inc a counter on the server
serverUrl = YNPREFBRANCH.getCharPref('serverurl');
if(yoonoGlob.firstRun) {
YOONO_CMPT.sendRequest(serverUrl + 'rest/counters/one/install/xpi', 'POST', 'async', '', null);
if(campaignId) {
var campaignString = campaignId + '-install-ff' ;
YOONO_CMPT.sendRequest(serverUrl + 'rest/counters/one/campaign/' + campaignString, 'POST', 'async', '', null);
}
}
// update flag for next time...
YNPREFBRANCH.setBoolPref("firstrun", false);
this.requestProcessed = false;
yoonoGlob.externalInterfaces = yoono.yextif;
// create the instance to manage the sidebar.
// Its init method will be called each time the sidebar is opened, and its uninit method
// each time it is closed.
// The YoonoSidebar class is declared in sidebar.js (loaded in main document), and enriched in
// sidebarPanel.js, loaded in sidebarPanel.xul document when sidebar is opened
yoonoGlob.sidebar = new YoonoSidebar(yoonoGlob.externalInterfaces);
yoonoGlob.MemoMgr = yoonoGlob.externalInterfaces.methods.getMemoMgr();
yoonoGlob.MemoMgr.getList(null);
yoonoGlob.gStrbundle=document.getElementById("yoono-strings");
uninstallObserver.register();
ynTabbrowserListener.init();
// Afficher d'éventuels nouveaux boutons apparus depuis la derniere version installée
// (qui sinon n'apparaissent pas en cas de customisation)
yoonoGlob.updateInterface();
attachYoonoBkmMenu('toolbar');
markPrivateFolders();
// Add a mouseup listener to store the focused window when a selection is done,
// So that selection can be accessed when clicking on a shortcut in the sidebar
// (which changes the focused window !!)
var content = document.getElementById('content');
var panel = content.mPanelContainer;
var _self = this;
panel.addEventListener('mouseup', function(evt) {_self.mouseUpHandler(evt)}, true);
// code below is just an investigation, not used for now
// panel.addEventListener('mousemove', function(evt) {_self.mouseMouveHandler(evt)}, true);
} catch(e) {
// we don't use yoono.log because it does'nt work at this time :/
var CONSOLESERVICE = YOONO_CL["@mozilla.org/consoleservice;1"].getService(YOONO_CI.nsIConsoleService);
CONSOLESERVICE.logStringMessage(" ### MAIN OVERLAY INIT EXCEPTION : \n "+e+"\n"+e.stack+"\n ###\n");
}
},
// Memorize the focused window, so that it is available when querying the selection even if focuse has changed
mouseUpHandler : function(evt) {
var focusedWindow = document.commandDispatcher.focusedWindow;
var content = document.getElementById('content');
if (focusedWindow == window)
focusedWindow = content;
yoonoGlob.focusedWindow = focusedWindow;
},
// Memorize the focused window, so that it is available when querying the selection even if focuse has changed
mouseMouveHandler : function(aEvent) {
if(yoonoGlob.mouseOverTimer) {
clearTimeout(yoonoGlob.mouseOverTimer);
yoonoGlob.mouseOverTimer = null;
}
var textContent = aEvent.rangeParent.textContent;
var rangeOffset = aEvent.rangeOffset ;
var _self = this;
yoonoGlob.mouseOverTimer = setTimeout(function() {
_self.processMouseMove(textContent, rangeOffset);
}, 500);
},
processMouseMove : function(textContent, aRangeOffset) {
var words = textContent.replace(/[\.\?,;:\/!=+]/g, ' ');
var begining = words.substr(0, aRangeOffset);
var ending = words.substr(aRangeOffset);
var firstCharOffset = begining.lastIndexOf(' ') + 1 ;
var wordBegining = begining.substr(firstCharOffset);
var lastCharOffset = ending.indexOf(' ');
var wordEnding = ending.substr(0, lastCharOffset);
var word = wordBegining + wordEnding;
yoonoGlob.debug('MOUSEOVER: ' + word);
},
// Désabonnement aux événements
uninit: function() {
ynTabbrowserListener.uninit();
uninstallObserver.deregister();
if(yoonoGlob.sidebar.visible) {
yoonoGlob.sidebar.win.ynSidebar.saveConfig();
}
YOONO_LOG.debug("Closing popouted yoodgets from extension");
yoonoGlob.externalInterfaces.goodbye();
},
uninstallFromButton: function() {
var gExtensionManager = Components.classes["@mozilla.org/extensions/manager;1"].getService(Components.interfaces.nsIExtensionManager);
var YOONO_ID = "{d9284e50-81fc-11da-a72b-0800200c9a66}"; // à remplacer lorsque l'objet centralisant le yoono id sera prêt
var item = gExtensionManager.getItemForID(YOONO_ID);
yoono.main.addStat(['clic.yoonobutton.uninstall'], 1);
gExtensionManager.uninstallItem(YOONO_ID);
},
}
function ynOpenChrome(uri, arg) {
yoonoGlob.debug('ynOpenChrome: ' + uri + ' ' + arg);
window.openDialog('chrome://yoono/content/dialogs/' + uri + '.xul', uri, 'chrome,modal', arg);
}
window.addEventListener("load", function() { yoonoObserver.init(); }, false);
window.addEventListener("unload", function() { yoonoObserver.uninit(); }, false);